home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / Prog / T / ToolsPlus 2.1.sit / Tools Plus 2.1 ƒ / Tools Plus 2.1 (C & Pascal) / User Manual / 06-Buttons < prev    next >
Encoding:
Text File  |  1993-10-24  |  18.7 KB  |  298 lines  |  [TEXT/ttxt]

  1. 6  Buttons
  2. ``````````
  3.  
  4.   Tools Plus supports the use of buttons on any window created by the WindowOpen procedure.  Buttons are created on the current window by the NewButton procedure.  Each button is referenced by a unique button number, which can be from 1 to 255.  This number is specified when the button is created, and refers to the specific button until that button is deleted.  Note that the button number is related to its associated window.  This means that two different windows can each have a button numbered “1” without interfering with each other.  Whenever a button is clicked by the user, the PollSystem function reports the button number as well as its window number.
  5.  
  6.   When a button is no longer required, it is deleted by the DeleteButton procedure, which releases the memory used by that button.  This is done automatically if a window is closed.  Buttons can be renamed by using the ButtonTitle procedure.
  7.  
  8.  
  9.  
  10.  
  11.  
  12. Button Types
  13. ````````````
  14.   All three types of Macintosh buttons are supported by Tools Plus (push-button, radio button and check-box).  The push-button is clicked when the user wants to select it.  A push button is always used to “do something right now,” such as confirming or canceling a process.
  15.  
  16.   Check boxes and radio buttons are variations on a similar theme: they can be either selected or deselected by clicking on them.  The check box contains and “x” when checked, whereas the radio button contains a dot.  The difference between these two buttons is that radio buttons are logically grouped by your application such that only one button can be selected within the group.  When the user selects a radio button, your application de-selects the other buttons in the group.
  17.  
  18.  
  19.  
  20.  
  21.  
  22. Button States
  23. `````````````
  24.   All three button types can be either enabled or disabled by using the EnableButton procedure.  When a button is disabled, it becomes dim and cannot be selected by the user.  Check boxes and radio buttons can be either selected or de-selected by using the SelectButton procedure.
  25.  
  26.   When a window is inactive, all the associated buttons are automatically disabled and cannot be selected.  When the window is activated, the buttons are automatically returned to their normal state as set by your application.
  27.  
  28.  
  29.  
  30.  
  31.  
  32. Button Titles
  33. `````````````
  34.   A button’s title can be changed by the ButtonTitle procedure, however this should be done judicially since this can be confusing to the user.  A button’s title is centered in a push button, and left aligned in a check box or radio button.
  35.  
  36.  
  37.  
  38.  
  39.  
  40. Default Button
  41. ``````````````
  42.   One push button on each window can be designated to be the “default” button by the SetDefaultButton procedure.  This procedure draws an outline around the button.  If the Return or Enter key is pressed, Tools Plus responds as if the default button had been clicked.  The button’s default status can be cleared by the NoDefaultButton procedure.
  43.  
  44.  
  45.  
  46.  
  47.  
  48. Handling Buttons
  49. ````````````````
  50.   Your application specifies if check boxes or radio buttons are selected or not.  It also specifies if a button is enabled or disabled.  When a window in inactive, Tools Plus disables all buttons.  When the window is activated again, all the buttons regain their correct status as specified by your application.
  51.  
  52.   The PollSystem function is used to constantly inquire about any events that have occurred, including clicking on buttons.  If a button is selected (i.e. the user presses the mouse button down and releases it within the button’s region), it is reported by PollSystem.  In the case of check boxes or radio buttons, your application must then select or de-select the button appropriately.
  53.  
  54.   When working with Radio Buttons, Tools Plus doesn’t know how these buttons are grouped, and therefore does not automatically turn off other radio buttons.  Your application must handle this.
  55.  
  56. Warning: If you have obtained a handle to a button, do not change any of
  57.          the fields in the button’s record.
  58.  
  59. ------------------------------------------------------------------------
  60.  
  61. NewButton
  62. `````````
  63. Create a new button.
  64.  
  65.    pascal void NewButton (int Button, int left, int top, int right,
  66.                  int bottom, Str255 Title, int procID,
  67.                  Boolean EnabledFlag, Boolean SelectedFlag);
  68.  
  69.    procedure NewButton(Button, left, top, right, bottom: INTEGER;
  70.                  Title: STRING; procID: INTEGER;
  71.                  EnabledFlag, SelectedFlag: BOOLEAN);
  72.  
  73.   Button specifies the button number (from 1 to 255) that will be created in the current window.  Once a button is created, it will be referenced by this button number.  If a button has been previously created in the current window using the same number, it will be replaced with a new button as specified by the parameters in the NewButton procedure.  If the current window doesn’t belong to your application, or if no windows are open, NewButton does nothing.
  74.  
  75.   Left, top, right, and bottom define a rectangle in local co-ordinates that determines the button’s size and location in the window.  These parameters can be seen as two corners; the upper left-hand corner (left,top) and the bottom right-hand corner (right,bottom).  See the chart below regarding the minimum height for buttons.  These measurements are based on using the system font (Chicago) for the button’s text.
  76.  
  77.                               Minimum Height            Standard
  78.                       With Descenders  No Descenders     Height
  79.    Push Buttons               18           13              20
  80.    Radio/Check Box Buttons    146          12              16
  81.  
  82.  
  83.   The Title parameter is the button’s title.  Each button should have a unique title.  Button titles can have multiple lines, each line being separated by the ASCII character code $0D (carriage return).  It is your responsibility to ensure that the rectangle defining the button’s co-ordinates is sufficient to contain the button’s title.
  84.  
  85.   ProcID is the button definition ID, which specifies the button’s appearance and behavior.  The following are the three standard button definitions.
  86.       pushButProc  = push-button
  87.       checkBoxProc = check box
  88.       RadioButProc = radio button
  89.  
  90.   The EnabledFlag indicates if the newly created button is enabled or not.  All three button types can be either enabled or disabled.  When a button is disabled, it becomes dim and cannot be selected by the user.  All buttons automatically become disabled when the window containing them is inactive.  When the window is activated, the buttons assume their state as set by the NewButton procedure and subsequent calls to the EnableButton procedure.  The two constants that can be used for this flag are enabled and disabled.
  91.  
  92.   The SelectedFlag indicates if the newly created button is selected or not.  Only check boxes and radio buttons can be selected (this setting has no effect on push buttons).  The two constants that can be used for this flag are selected and notSelected.
  93.  
  94.  
  95.  
  96. Fonts
  97. `````
  98.   By default, all buttons are drawn using the system font (Chicago, 12 point).  Buttons can also be drawn using an alternate font by adding the constant useWFont to the procID (i.e. pushButProc + useWFont).  The first time this is done in a window, the window’s current font, size and styling settings (as set by the TextFont, TextSize, and TextFace procedures) are saved as the alternate button font for the window.  The window’s settings can then be changed without affecting any buttons.  Subsequently created buttons that include the useWFont constant in their ProcID, will use the existing alternate button font regardless of the window’s current settings.
  99.  
  100.  
  101.  
  102. Default Button
  103. ``````````````
  104.   When specifying the ProcID, you can optionally make one of the push buttons the “default” for the window.  The default button is automatically selected if the user presses the “Return” key or “Enter” key.  To make a button the default, specify a ProcID of pushButProc + DefaultButton, or simply use DefaultButton as a procID.  A black outline is drawn around the default button.  The outline is automatically grayed out whenever the default button is disabled.
  105.  
  106.   If a default button already exists in the current window and you specify another button, the original one loses its “default” status.  Note that only 1 button can be the default in each window, and that it must be a push button.
  107.  
  108. Note: Tools Plus makes no attempt to control the placement of buttons or
  109.       to protect them once they have been created.  It is the
  110.       programmer’s responsibility to ensure that buttons are of
  111.       sufficient size to contain their title, and that their placement
  112.       within the window is reasonable and does not conflict with other
  113.       objects.  Furthermore, you should not allow the application’s text
  114.       and drawing processes to interfere with buttons, or with the
  115.       “default button” frame.  Windows with a “size box” should not
  116.       allow buttons to be obscured or hidden by making the window too
  117.       small.
  118.  
  119. Also see:  NewButtonRect.
  120.  
  121.   CONST                   {Button definition IDs                   }
  122.     pushButProc  =0;      {Push button                             }
  123.     checkBoxProc =1;      {check box                               }
  124.     RadioButProc =2;      {radio button                            }
  125.     DefaultButton=4;      {default push button (1 only per window) }
  126.     useWFont     =8;      {added to ProcID to use the window’s font}
  127.                           {Button state…                           }
  128.     enabled      =true;   {enable button                           }
  129.     disabled     =false;  {disable button                          }
  130.     selected     =true;   {select (check) button                   }
  131.     notSelected  =false;  {deselect (un-check) button              }
  132.  
  133. ------------------------------------------------------------------------
  134.  
  135. NewButtonRect
  136. `````````````
  137. Create a new button.
  138.  
  139.    pascal void NewButtonRect (int Button, Rect *Bounds, Str255 Title,
  140.                  int procID, Boolean EnabledFlag, Boolean SelectedFlag);
  141.  
  142.    procedure NewButtonRect(Button: INTEGER; Bounds: RECT; Title: STRING;
  143.                  procID: INTEGER; EnabledFlag, SelectedFlag: BOOLEAN);
  144.  
  145.   NewButtonRect is identical to the NewButton procedure, except that it accepts the Bounds rectangle in place of the individual left, top, right and bottom co-ordinates.
  146.  
  147. ------------------------------------------------------------------------
  148.  
  149. DeleteButton
  150. ````````````
  151. Delete a button.
  152.  
  153.    pascal void DeleteButton (int Button);
  154.  
  155.    procedure DeleteButton(Button: INTEGER);
  156.  
  157.   Button specifies the button number (from 1 to 255) that is deleted from the current window.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, DeleteButton does nothing.
  158.  
  159. ------------------------------------------------------------------------
  160.  
  161. EnableButton
  162. ````````````
  163. Enable or disable a button.
  164.  
  165.    pascal void EnableButton (int Button, Boolean EnabledFlag);
  166.  
  167.    procedure EnableButton(Button: INTEGER; EnabledFlag: BOOLEAN);
  168.  
  169.   Button specifies the button number (from 1 to 255) that is affected in the current window.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, EnableButton does nothing.
  170.  
  171.   The EnabledFlag indicates if the button is enabled or not.  All three button types can be either enabled or disabled.  When a button is disabled, it becomes dim and cannot be selected by the user.  All buttons automatically become disabled when the window containing them is inactive.  When the window is activated, the buttons assume their state as set by the NewButton procedure, and subsequent calls to the EnableButton procedure.  The two constants that can be used for this flag are enabled and disabled.
  172.  
  173.   CONST                   {Button state                           }
  174.     enabled     =true;    {button is enabled                      }
  175.     disabled    =false;   {button is disabled                     }
  176.  
  177.   See the NewButton procedure for additional information pertaining to the button’s enabling, disabling, and selection (i.e. checked or not).
  178.  
  179. ------------------------------------------------------------------------
  180.  
  181. SelectButton
  182. ````````````
  183. Select or deselect (check or un-check) a button.
  184.  
  185.    pascal void SelectButton (int Button, Boolean SelectedFlag);
  186.  
  187.    procedure SelectButton(Button: INTEGER; SelectedFlag: BOOLEAN);
  188.  
  189.   Button specifies the button number (from 1 to 255) that is affected in the current window.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, SelectButton does nothing.
  190.  
  191.   The SelectedFlag indicates if the button is selected (checked) or not.  Only check boxes and radio buttons can be selected.  This setting has no effect on push buttons.  The two constants that can be used for this flag are selected and notSelected.
  192.  
  193.   CONST                   {Button state                           }
  194.     selected    =true;    {button is selected (checked)           }
  195.     notSelected =false;   {button is not selected (not checked)   }
  196.  
  197.   See the NewButton procedure for additional information pertaining to the button’s enabling, disabling, and selection (i.e. checked or not).
  198.  
  199. ------------------------------------------------------------------------
  200.  
  201. ButtonIsEnabled
  202. ```````````````
  203. Determine if a button is enabled or disabled.
  204.  
  205.    pascal Boolean ButtonIsEnabled (int Button);
  206.  
  207.    function ButtonIsEnabled(Button: INTEGER): BOOLEAN;
  208.  
  209.   Button specifies the button number (from 1 to 255) which is queried in the current window.
  210.  
  211.   The function’s value returns true if the button is enabled, and false if the button is disabled.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, ButtonIsEnabled returns false.
  212.  
  213.   CONST                   {Button state                           }
  214.     enabled     =true;    {button is enabled                      }
  215.     disabled    =false;   {button is disabled                     }
  216.  
  217.   See the NewButton procedure for additional information pertaining to the button’s enabling, disabling, and selection (i.e. checked or not).
  218.  
  219. Note: ButtonIsEnabled returns the button’s state as though the button’s
  220.       window is active.  This is the case even when the window is
  221.       deactivated and all the buttons appear disabled.
  222.  
  223. ------------------------------------------------------------------------
  224.  
  225. ButtonIsSelected
  226. ````````````````
  227. Determine if a button is selected (i.e. checked).
  228.  
  229.    pascal Boolean ButtonIsSelected (int Button);
  230.  
  231.    function ButtonIsSelected(Button: INTEGER): BOOLEAN;
  232.  
  233.   Button specifies the button number (from 1 to 255) that is queried in the current window.
  234.  
  235.   The function’s value returns true if the button is selected (checked), and false if the button is not selected.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, ButtonIsSelected returns false.
  236.  
  237.   CONST                   {Button state                           }
  238.     selected    =true;    {button is selected (checked)           }
  239.     notSelected =false;   {button is not selected (not checked)   }
  240.  
  241.   See the NewButton procedure for additional information pertaining to the button’s enabling, disabling, and selection (i.e. checked or not).
  242.  
  243. ------------------------------------------------------------------------
  244.  
  245. ButtonTitle
  246. ```````````
  247. Change a button’s title.
  248.  
  249.    pascal void ButtonTitle (int Button, Str255 Title);
  250.  
  251.    procedure ButtonTitle(Button: INTEGER; Title: string);
  252.  
  253.   Button specifies the button number (from 1 to 255) that is affected in the current window.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, ButtonTitle does nothing.
  254.  
  255.   The Title parameter is the button’s title.  Each button should have a unique title.  Button titles can have multiple lines, each line being separated by the ASCII character code $0D (carriage return).  Note that a button’s size does not change automatically to accommodate larger or smaller titles.
  256.  
  257. ------------------------------------------------------------------------
  258.  
  259. FlashButton
  260. ```````````
  261. Flash a button as though it was clicked by the user.
  262.  
  263.    pascal void FlashButton (int Button);
  264.  
  265.    procedure FlashButton(Button: INTEGER);
  266.  
  267.   Button specifies the button number (from 1 to 255) that is affected in the active window.  If the active window doesn’t belong to your application, or if no windows are open, FlashButton does nothing.
  268.  
  269.   FlashButton can be used in some specific instances.  Advanced programmers may decide to display a modal window when the Macintosh is busy with a lengthy process.  If a button (such as “Cancel”) on this window is equivalent to typing Command-., the button should be flashed when a Command-. is reported by PollSystem.  This makes the user feel that the key triggered the button.  Another example is double-clicking in a list box; this action can be interpreted as “select line and OK” in which case the OK button should be flashed.  This also occurs if your application interprets double-clicking a radio button as “select button and OK.”
  270.  
  271. ------------------------------------------------------------------------
  272.  
  273. SetDefaultButton
  274. ````````````````
  275. Set a button to be a window’s “default” button.
  276.  
  277.    pascal void SetDefaultButton (int Button);
  278.  
  279.    procedure SetDefaultButton(Button: INTEGER);
  280.  
  281.   Button specifies the button number (from 1 to 255) that will become the new default button in the current window.  If the current window doesn’t belong to your application, or if no windows are open, SetDefaultButton does nothing.  Also, if Button specifies a button that is not a push button, or a button that does not exist, SetDefaultButton does nothing.
  282.  
  283.   The default button is automatically selected if the user presses the “Return” key or “Enter” key.  A black outline is automatically drawn around the default button when the window is active.  If another default button already exists in the current window, it loses its “default” status.  Note that only 1 button can be the default in each window.
  284.  
  285. ------------------------------------------------------------------------
  286.  
  287. NoDefaultButton
  288. ```````````````
  289. Remove “default button” status for a window.
  290.  
  291.    pascal void NoDefaultButton(void);
  292.  
  293.    procedure NoDefaultButton;
  294.  
  295.   This procedure removes the “default button” status from the current window (i.e. a specific button will not be automatically selected when the user presses the “Return” key or “Enter” key).  The black outline that is automatically drawn around the default button is removed.  Buttons themselves, however, are not altered.  If the current window doesn’t belong to your application, or if no windows are open, NoDefaultButton does nothing.
  296.  
  297. ------------------------------------------------------------------------
  298.